package com.zyb.qiyu.live.api.controller;

import com.zyb.qiyu.user.dto.UserDTO;
import com.zyb.qiyu.user.interfaces.IUserRpc;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @ClassName UserController
 * @Author zhaoyb
 * @Date 2024-01-15
 * @Version 1.0
 */
@RestController
@RequestMapping("/user")
public class UserController {
    @DubboReference
    private IUserRpc userRpc;

    @GetMapping("/getUserById")
    public UserDTO getUserById(Long userId) {
        UserDTO dto = userRpc.getByUserId(userId);
//        System.out.println(dto.toString());
        return dto;
    }

    @GetMapping("/updateUserInfo")
    public boolean updateUserInfo(Long userId, String nickName) {
        UserDTO userDTO = new UserDTO();
        userDTO.setUserId(userId);
        userDTO.setNickName(nickName);
        return userRpc.updateUserInfo(userDTO);
    }

    @GetMapping("/insertOne")
    public boolean insertOne(Long userId) {
        UserDTO userDTO = new UserDTO();
        userDTO.setUserId(userId);
        userDTO.setNickName("nickName-test");
        userDTO.setSex(1);
        return userRpc.insertUserInfo(userDTO);
    }

    @GetMapping("/test")
    public String test() {
        return userRpc.test();
    }
}
